function e(e, t, o) {
    return t in e ? Object.defineProperty(e, t, {
        value: o,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : e[t] = o, e;
}

var t = function(e) {
    return e && e.__esModule ? e : {
        default: e
    };
}(require("../../utils/util")), o = require("./mobile-util"), n = {
    DEFAULT: 0,
    VERIFY_SUCCESS: 1,
    VERIFY_FAIL: 2
}, a = 0, i = !0;

Component({
    options: {
        multipleSlots: !0
    },
    properties: {
        enabledLabel: {
            type: Boolean,
            value: !0
        },
        appName: {
            type: String,
            value: "site"
        },
        mobile: {
            type: String,
            value: "",
            observer: function(e, t) {
                var o = {};
                i && (o = {
                    enabledMobileGet: !1,
                    customButton: !0,
                    mobileVerifyState: n.VERIFY_SUCCESS
                }), o["form.mobile"] = e, this.setData(o), this.updateEnabledSendCode();
            }
        },
        codeLen: {
            type: String,
            value: 4
        },
        customButton: {
            type: Boolean,
            value: !1
        },
        isVerifyCode: {
            type: Boolean,
            value: !0
        },
        enabledMobileGet: {
            type: Boolean,
            value: !0
        },
        isShownSendBtn: {
            type: Boolean,
            value: !0
        }
    },
    data: {
        form: {
            mobile: "",
            code: ""
        },
        mobileVerifyStatus: n,
        mobileVerifyState: n.DEFAULT,
        enabledSendCode: !1,
        sendCodeButtonText: "验证手机",
        showVcodeInput: !1
    },
    ready: function() {
        i = !1;
    },
    detached: function() {
        i = !0, clearInterval(this.timer), clearInterval(this.countTimer);
    },
    methods: {
        onInput: function(t) {
            var o = t.detail, n = o.name, a = o.value;
            a = a.trim(), this.setData(e({}, "form." + n, a)), "mobile" === n && this.updateEnabledSendCode(), 
            this.$emit("input", {
                name: n,
                value: a
            });
        },
        sendCode: function() {
            var e = this, t = this.data.form.mobile, n = this.startCountdown();
            (0, o.sendMobileCode)(t).then(function() {
                e.setData({
                    showVcodeInput: !0,
                    isVerifyCode: !0
                });
            }).catch(function() {
                n(), e.updateSendCodeStatusByCountDown(), e.$emit("fail", {
                    value: "短信发送失败，请重试"
                });
            });
        },
        updateEnabledSendCode: function() {
            var e = this.data.form, o = e.fastverify, n = e.mobile;
            this.setData({
                enabledSendCode: !o && (t.default.isMobile(n) && 0 === a)
            });
        },
        updateSendCodeStatusByCountDown: function() {
            var e = 0 === a ? "重新验证" : a + "S";
            this.setData({
                sendCodeButtonText: e
            }), 0 !== a && 60 !== a || this.updateEnabledSendCode();
        },
        startCountdown: function() {
            var e = this, t = void 0;
            return a = 60, this.updateSendCodeStatusByCountDown(), t = this.countTimer = setInterval(function() {
                a--, e.updateSendCodeStatusByCountDown(), 0 === a && clearInterval(t);
            }, 1e3), function() {
                a = 0, clearInterval(t);
            };
        },
        bindMobileGet: function(e) {
            var t = this;
            (0, o.resolverWxMobile)(e.detail, this.data.appName || "site").then(function(e) {
                var o = e.data.phoneNumber;
                t.setData({
                    enabledMobileGet: !1,
                    "form.mobile": o,
                    "form.fastverify": 1,
                    sendCodeButtonText: "验证成功",
                    mobileVerifyState: n.VERIFY_SUCCESS
                }), t.$emit("input", {
                    name: "mobile",
                    value: o
                });
            }, function() {
                t.$emit("fail", {
                    value: "快速获取失败，请手动输入"
                }), t.setData({
                    enabledMobileGet: !1,
                    showVcodeInput: t.data.isVerifyCode
                });
            });
        },
        verifyForm: function() {
            var e, o = this.data, n = o.form, a = o.showVcodeInput, i = o.codeLen;
            if (!n.fastverify) return n.mobile ? t.default.isMobile(n.mobile) ? a && (e = n.code ? n.code.length === i ? "" : "请输入正确的验证码" : "请输入验证码") : e = "手机号格式不正确" : e = "请输入手机号", 
            e;
        },
        getFormData: function() {
            var e = this.verifyForm();
            return e ? this.$emit("fail", {
                value: e
            }) : this.data.form;
        },
        $emit: function(e, t) {
            this.triggerEvent(e, t, {});
        }
    }
});